package org.ravenhearte.hardboild.gui;

import java.util.HashMap;

import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;

public class TextButton extends TextElement implements Button {
	private HashMap<String, ColorRGBA> states;
	private boolean pressed;
	
	public TextButton(String name, ColorRGBA color, int height) {
		super(name, color, height);
		states = new HashMap<String, ColorRGBA>();
	}
	
	public void setState(String state, ColorRGBA color) {
		states.put(state, color);
	}
	
	@Override
	public boolean contains(int x, int y) {
		Vector3f loc = spatial.getWorldTranslation();
		if ((x > loc.x) && (x < loc.x + getWidth())
		&& (y > loc.y) && (y < loc.y + getHeight())) {
			return true;
		}
		else {
			return false;
		}
	}
	
	@Override
	public boolean isPressed() {
		return pressed;
	}

	@Override
	public void onMouseOver() {
		setColor(states.get("MouseOver"));
	}

	@Override
	public void onMouseOut() {
		setColor(states.get("MouseOut"));		
	}

	@Override
	public void onMouseClick() {
		pressed = true;
		setColor(states.get("MouseClick"));		
	}

	@Override
	public void onMouseRelease() {
		pressed = false;
		setColor(states.get("MouseOver"));		
	}
}
